<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>博客</title>
    <link href="/css/main.css" rel="stylesheet" type="text/css">
    <link href="/fontAwesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
</head>

<body>

    <header>
        <div class="backimg"><img src="/images/top.jpg"></div>
    </header>

    <nav>
        <div class="menu">
            <% if(category === ''){ %>
            <a href="/" class="focus">首页</a>
            <% }else{ %>
            <a href="/">首页</a>
            <% } %>

            <% for(var cate of categories){ %>
            <% if (category === cate.id){ %>
            <a href="/?category=<%= cate.id %>" class="focus"><%= cate.name %></a>
            <% }else{ %>
            <a href="/?category=<%= cate.id %>"><%= cate.name %></a>
            <% } %>
            <% } %>
        </div>
    </nav>
    <main class="clear">
        <div class="mainLeft">

            <% for(var article of articles){ %>
            <div class="listBox">
                <h1><%= article.title%></h1>
                <p class="colDefault">
                    作者：<span class="colInfo"><%= article.user.username%></span> -
                    时间：<span class="colInfo"><%= article.addTime%></span> -
                    阅读：<span class="colInfo"><%= article.viewAmount%></span> -
                    评论：<span class="colInfo"><%= article.comments.length%></span>
                </p>
                <dfn><p><%= article.description%></p></dfn>
                <div class="function"><a href="/view?articleid=<%= article.id%>">阅读全文</a></div>
            </div>
            <% } %>

            <div class="pager">
                <ul class="clear">

                    <li class="previous">
                        <% if(page <=1){ %>
                        <span>没有上一页了</span>
                        <% }else{  %>
                        <a href="/?category=<%= category%>&page=<%= page-1%>">上一页</a>
                        <% } %>
                    </li>

                    <% if(maxPageNumber > 0){ %>
                    <li>
                        <strong><%= page%>/ <%= maxPageNumber%></strong>
                    </li>
                    <% } %>

                    <li class="next">
                        <% if(page >= maxPageNumber){ %>
                        <span>没有下一页了</span>
                        <% }else{ %>
                        <a href="/?category=<%= category%>&page=<%= page+1%>">下一页</a>
                        <% } %>
                    </li>

                </ul>
            </div>
        </div>
        <div class="mainRight">
            <!-- show user div or login/register based on whether backend passed user data -->
            <% if(user){ %>
            <div class="rightBox" id="user">
                <div class="title"><span>用户信息</span></div>
                <p><span class="colDark username"><%= user.username %></span></p>
                <% if(user.isAdmin){ %>
                <p><span class="colDanger info">welcome Admin, </span><a href="/admin">enter admin</a></p>
                <% }else{ %>
                <p><span class="colDanger info">welcome to my blog!</span></p>
                <% } %>
                <p><span class="colDark" id="logout"><a href="javascript:">log out</a></span></p>
            </div>
            <% }else{ %>
            <div class="rightBox" id="loginBox">
                <div class="title"><span>登录</span></div>
                <div class="line"><span class="colDark">用户名：</span><input name="username" type="text" value="admin" /><em></em></div>
                <div class="line"><span class="colDark">密码：</span><input name="password" type="password" value="admin"/><em></em></div>
                <div class="line"><span class="colDark"></span><button>登 录</button></div>
                <p class="textRight">还没注册？<a href="javascript:;" class="colMint">马上注册</a></p>
                <p class="colWarning textCenter"></p>
            </div>
            <div class="rightBox" id="registerBox" style="display: none;">
                <div class="title"><span>注册</span></div>
                <div class="line"><span class="colDark">用户名：</span><input name="username" type="text" /></div>
                <div class="line"><span class="colDark">密码：</span><input name="password" type="password" /></div>
                <div class="line"><span class="colDark">确认：</span><input name="repassword" type="password" /></div>
                <div class="line"><span class="colDark"></span><button>注 册</button></div>
                <p class="textRight">已有账号？<a href="javascript:;" class="colMint">马上登录</a></p>
                <p class="colWarning textCenter"></p>
            </div>
            <% } %>

            <div class="rightBox">
                <div class="title"><span>社区</span></div>
                <p><a href="http://google.com" target="_blank" class="colDanger">google</a></p>
                <p><a href="http://baidu.com" target="_blank" class="colDanger">baidu</a></p>
            </div>
        </div>
    </main>

    <div class="copyright textCenter">Copyright © Guanghui Wang</div>

</body>
<script src="/lib/jquery-1.12.4.min.js"></script>
<script src="/js/index.js"></script>
</html>
